package lvm

import "context"

// LVRename 逻辑卷重命名
func LVRename(ctx context.Context, vgName, oldName, newName string) (lv *LogicalVolume, err error) {
	lv = getLV(ctx, vgName, oldName)
	if lv == nil {
		err = ErrNotFound
		return
	}

	vg := getVG(ctx, lv.VGName)
	if vg == nil {
		err = ErrNotFound
		return
	}

	_, err = execCommand(ctx, "lvrename", vgName, oldName, newName)
	if err != nil {
		return
	}
	lv = getLV(ctx, vgName, newName)
	if lv == nil {
		err = ErrCommand
	}
	return
}
